package GUI.gameWin;

import gamePlus.client.Client;
import gamePlus.client.ClientRoundUnit;

import java.awt.Dimension;

import javax.swing.JFrame;
import javax.swing.JSplitPane;

import carddeck.Card;
import carddeck.Rank;
import carddeck.Suit;

import protocol.WaitTimeChange;

@SuppressWarnings("serial")
public class ClientGameWindow extends JFrame {
	private Client client;
	private ClientRoundUnit roundUnit;
	private static ClientGameWindow instance;
	
	private GamePanelPlus gamePanel;
	
	public ClientGameWindow(Client client, ClientRoundUnit roundUnit) {
		instance = this;
		this.client=client;
		this.roundUnit=roundUnit;
		setTitle("Makao! v1.00");
		setVisible(true);
		JSplitPane content = new JSplitPane() {
			@Override
			public void setDividerLocation(double proportionalLocation) {
				setDividerLocation(0);
			}
			@Override
			public void setDividerLocation(int location) {
				super.setDividerLocation(getWidth()-250);
			}
			@Override
			public int getDividerLocation() {
				return getWidth()-250;
			}
			@Override
			public int getLastDividerLocation() {
				return getWidth()-250;
			}
		};
		setContentPane(content);
		setMinimumSize(new Dimension(800,600));
		gamePanel = new GamePanelPlus(roundUnit);
		content.setLeftComponent(gamePanel);
		gamePanel.setPreferredSize(gamePanel.getMinimumSize());
		
		content.setEnabled(false);
		content.setDividerSize(1);
		content.setResizeWeight(1);
	}
	
	public static ClientGameWindow getInstance() {
		return instance;
	}
	
	public GamePanelPlus getGamePanel() {
		return gamePanel;
	}

	public ClientRoundUnit getRoundUnit() {
		return roundUnit;
	}
	
	public void requestAceSelection() {
		setEnabled(false);
		new AceSelectionDialogPlus(this, null).pack();
	}

	public void requestJackSelection() {
		setEnabled(false);
		new JackSelectionDialogPlus(null, this, null).pack();
	}
	
	public void selectAce(Suit color) {
		client.setColor(color);
	}
	
	public void selectJack(Rank demand) {
		client.setDemand(demand);
	}
	
	public Client getClient() {
		return client;
	}
	
	public void setButtonState(GameButtonPanel.GBState state) {
		gamePanel.getButtonPanel().switchState(state);
	}

	public void requestJokerSelection(Card theCard) {
		setEnabled(false);
		new JokerSelectionDialogPlus(instance, theCard).pack();
	}
}
